home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 5
/
The 640 Meg Shareware Studio CD-ROM Volume V (Data Express)(1994).ISO
/
amiga
/
showrv19.lha
/
showrev.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-02
|
13KB
|
495 lines
;/* execute me to compile
dcc showrev.c -proto -mi -r -mRR
quit
*/
/*
* ShowRev
*
* copyright 1994 by Christof Damian
*
* $Id: showrev.c,v 1.9 1994/03/02 18:32:05 damian Exp damian $
*
* $Source: Wⁿrg:home/damian/cc/RCS/showrev.c,v $
*
* $Revision: 1.9 $
*
* $Author: damian $
*
* $Log: showrev.c,v $
* Revision 1.9 1994/03/02 18:32:05 damian
* cosmetics
*
* Revision 1.8 1994/03/02 18:22:08 damian
* can take qualified now (instead of only filenames)
*
* Revision 1.7 1994/02/21 16:00:55 damian
* added fix for $VER without leading \0
*
* Revision 1.6 1994/02/09 12:30:18 damian
* better check between ident/Version
*
* Revision 1.5 1994/02/08 20:05:56 damian
* changed uident-check a little bit
*
* Revision 1.4 1994/02/03 17:17:12 damian
* added check for fileinfoblock (date,comment,flags)
*
* Revision 1.3 1994/02/02 20:36:27 damian
* changed uident-check, so it won't show up in ShowRev
*
* Revision 1.2 1994/02/02 20:33:43 damian
* added Id string
*
* Revision 1.1 1994/02/02 20:31:37 damian
* Initial revision
*/
/*** C= includes ***/
#include <exec/types.h>
#include <exec/memory.h>
#include <dos/dosextens.h>
#include <dos/stdio.h>
/*** DICE - includes ***/
#include <strings.h>
#include <ctype.h>
/*** library bases & protopragmas ***/
extern struct DosLibrary *DOSBase;
#define DOSBase_DECLARED
#include <proto/exec_protos.h>
#include <proto/dos_protos.h>
/*** global #defines ***/
#define Prototype GLOBAL
#define Local STATIC
#define CONST
struct PBLE
{
BPTR Next;
ULONG DirLock;
};
/*** prototypes of this file ***/
Local VOID Fail(char *text);
Local VOID Warning(char *text);
Local BOOL CheckResidentList(char *name,BOOL system);
Local BOOL CheckVersion(char *dir,char *file);
Local BOOL CheckVersionMulti(char *dir,char *file);
Prototype int main(int argc_notused,char **argv_notused);
#ifndef __COMMODORE_DATE__
#define __COMMODORE_DATE__ __DATE__
#endif
#define BASENAME "ShowRev"
#define MAXPATHLEN 512
#define MAXLINELEN 512
/*** for C= Version or ShowRev ***/
CONST STATIC char VER[] = "\0$VER: " BASENAME " 1.9 (" __COMMODORE_DATE__ ")";
CONST STATIC char Basename[] = BASENAME;
CONST STATIC char Id[] = "$Id: showrev.c,v 1.9 1994/03/02 18:32:05 damian Exp damian $";
BOOL CheckAll = FALSE; /* checks all found files */
BOOL Verbose = FALSE; /* verbose output */
int ReturnCode = RETURN_OK; /* main() return code */
/*
* VOID Fail(char *text)
*
* prints *text to Output() and sets ReturnCode can do with OS1.1
*
*/
VOID Fail(char *text)
{
CONST STATIC char header[] = BASENAME ": ";
CONST STATIC char footer[] = ".\n";
Write(Output(),header,sizeof(header)-1);
Write(Output(),text,strlen(text));
Write(Output(),footer,sizeof(footer)-1);
ReturnCode = RETURN_FAIL;
}
/*
* VOID Warning(char *text)
*
* prints *text to Output() and sets ReturnCode can do with OS1.1
*
*/
VOID Warning(char *text)
{
Fail(text);
ReturnCode = RETURN_WARN;
}
/*
* BOOL CheckResidentList(char *name,BOOL system)
*
* searches the system/normal residentlist for *name
*
* returns TRUE if found
*/
BOOL CheckResidentList(char *name,BOOL system)
{
struct Segment *segment;
LONG uc;
BOOL found = FALSE;
if (Verbose)
Printf("searching %ls in %ls resident list\n",name, system ? "system" : "normal");
Forbid();
if (segment = FindSegment(name,NULL,FALSE))
{
found = TRUE;
uc = segment->seg_UC;
};
Permit();
if (found)
{
Printf("%ls found in %ls resident list (",name, system ? "system" : "normal");
switch (uc)
{
case CMD_SYSTEM: Printf("system"); break;
case CMD_INTERNAL: Printf("internal"); break;
case CMD_DISABLED: Printf("disabled"); break;
default: Printf("usercount = %ld",uc); break;
};
Printf(")\n\n");
};
return found;
}
/*
* BOOL CheckVersion(char *dir,char *file)
*
* tries to open the file *file in dir *dir, and searches for one or more
* Commodore Version, RCS ident or DUUCP-uident strings and prints them
*
* returns TRUE if file is found
*/
BOOL CheckVersion(char *dir,char *file)
{
char buffer[MAXPATHLEN];
strcpy(buffer,dir);
AddPart(buffer,file,MAXPATHLEN);
if (Verbose)
Printf("searching %ls in %ls\n",file,buffer);
BPTR fh = Open(buffer,MODE_OLDFILE);
if (fh)
{
/* get realname block */
{
char realname[MAXPATHLEN];
if (!NameFromFH(fh,realname,sizeof(realname)))
strcpy(realname,buffer);
Printf("found %ls:\n ", realname);
}
/* examine fib block */
{
struct FileInfoBlock *fib = AllocVec(sizeof(struct FileInfoBlock),MEMF_ANY);
if (fib)
{
if (ExamineFH(fh,fib))
{
char strday[LEN_DATSTRING];
char strdate[LEN_DATSTRING];
char strtime[LEN_DATSTRING];
struct DateTime datetime;
datetime.dat_Format = FORMAT_DOS;
datetime.dat_Flags = 0;
datetime.dat_StrDay = strday;
datetime.dat_StrDate = strdate;
datetime.dat_StrTime = strtime;
CopyMem(&fib->fib_Date,&datetime.dat_Stamp,sizeof(struct DateStamp));
char protection[8];
protection[7] = '\0';
protection[6] = (fib->fib_Protection & 1) ? '-' : 'd';
protection[5] = (fib->fib_Protection & 2) ? '-' : 'e';
protection[4] = (fib->fib_Protection & 4) ? '-' : 'w';
protection[3] = (fib->fib_Protection & 8) ? '-' : 'r';
protection[2] = (fib->fib_Protection & 16) ? 'a' : '-';
protection[1] = (fib->fib_Protection & 32) ? 'p' : '-';
protection[0] = (fib->fib_Protection & 64) ? 's' : '-';
if (DateToStr(&datetime))
Printf("%ls %ls %ls ", strday,strdate,strtime);
Printf("%ls %ld bytes %ls", protection, fib->fib_Size, fib->fib_Comment);
};
FreeVec(fib);
};
}
WriteChar('\n');
/* examine binary block */
{
BOOL one = FALSE; /* indicates a least one version string found */
LONG first;
while ((first = FGetC(fh))!=-1)
{
char temp[MAXLINELEN];
if (first=='$' || first=='@')
{
char last = first;
LONG len = 1;
temp[0] = first;
LONG c;
while ((c = FGetC(fh))!=-1)
{
temp[len++] = c;
if (first=='@' && temp[1]!='(')
break;
if (c=='\0' || c=='\n' || (len==MAXLINELEN-1) || (c=='$' && first=='$'))
{
if (c=='$' && first=='$' && len>6)
if (strncmp(&temp[1],"VER: ",5)==0)
continue;
last = c;
break;
};
};
if (temp[len-1]=='\n') /* cut off newline */
len--;
temp[len] = '\0';
if (first=='$' && (strncmp(&temp[1],"VER: ",5)==0) && (last=='\0' || last=='\n')) /* C= VER */
{
Printf(" Version : %ls\n", temp);
one = TRUE;
}
else if (first=='@' && (strncmp(&temp[1],"($)",3)==0) && last=='\0') /* uident */
{
Printf(" uident : %ls\n", temp);
one = TRUE;
}
else
{
if (first=='$' && last=='$') /* RCS ident */
{
int i=1;
while (isalpha(temp[i]) && i<len)
i++;
if (temp[i]==':')
{
Printf(" ident : %ls\n", temp);
one = TRUE;
};
};
};
};
};
if (!one)
Printf(" no version string found\n");
}
if (!Close(fh))
Warning("closing file error");
WriteChar('\n');
return TRUE;
};
return FALSE;
}
/*
* BOOL CheckVersionMulti(char *dir,char *file)
*
* checks if *dir ends in ':' and checks for multiassigns if it is.
* calls CheckVersion() for every found directory
*
* returns TRUE if at least one CheckVersion() returns TRUE
*/
BOOL CheckVersionMulti(char *dir,char *file)
{
if (strlen(dir)>0)
{
if (dir[strlen(dir)-1]==':')
{
BOOL found = FALSE;
struct DevProc *devproc = NULL;
if (devproc = GetDeviceProc(dir,NULL))
if (devproc->dvp_Lock)
{
devproc = NULL;
if (Verbose)
Printf("checking multiassigns for %ls\n",dir);
while (devproc = GetDeviceProc(dir,devproc))
{
if (devproc->dvp_Lock)
{
char buffer[MAXPATHLEN];
if (NameFromLock(devproc->dvp_Lock,buffer,sizeof(buffer)))
{
if (found = CheckVersion(buffer,file))
if (!CheckAll)
return TRUE;
}
else
Warning("NameFromLock() failed");
};
};
if (Verbose)
Printf("\n");
}
else
found = CheckVersion(dir,file);
return found;
};
};
return CheckVersion(dir,file);
}
/*
* ShowRev
*
* int main(int argc_notused,char **argv_notused)
*
*/
int main(int argc_notused,char **argv_notused)
{
if (DOSBase->dl_lib.lib_Version >= 37) /* at least AmigaOS 2.04 required */
{
LONG array[] = { NULL, FALSE, FALSE, FALSE };
struct RDArgs *rdargs = ReadArgs("NAME/A,ALL/S,VERBOSE/S",array,NULL);
if (rdargs)
{
STRPTR filename = (STRPTR)array[0];
CheckAll = array[1];
Verbose = array[2];
struct Task *task = FindTask(NULL);
if (task->tc_Node.ln_Type==NT_PROCESS) /* should be TRUE for a CLI-command */
{
struct CommandLineInterface *CLI = BADDR(((struct Process *)task)->pr_CLI);
if (CLI) /* should be true for a CLI-command too */
{
Printf("%ls\n\n",&VER[7]);
BOOL found = FALSE;
if (FilePart(filename)!=filename) /* is this path qualified ? */
{
if (CheckVersion("",filename)) /* yes! so check it directly (worx only with 37 and up) */
found = TRUE;
filename = FilePart(filename); /* now its unqualified */
};
if (!found || CheckAll)
{
if (CheckResidentList(filename,FALSE))
found = TRUE;
if (!found || CheckAll)
{
if (CheckResidentList(filename,TRUE))
found = TRUE;
if (!found || CheckAll)
{
if (CheckVersion("",filename))
found = TRUE;
if (!found || CheckAll)
{
struct PBLE *pble = BADDR(CLI->cli_CommandDir); /* PATH-list */
while (pble)
{
char buffer[MAXPATHLEN];
if (NameFromLock(pble->DirLock,buffer,sizeof(buffer)))
{
if (CheckVersionMulti(buffer,filename))
found = TRUE;
}
else
Warning("NameFromLock() failed");
if (found && !CheckAll)
break;
pble = BADDR(pble->Next); /* check next path */
};
if (!found || CheckAll)
if (CheckVersionMulti("C:",filename))
found = TRUE;
};
};
};
};
if (!found)
Warning("no version found, file not in path");
}
else
Fail("not a CLI-process");
}
else
Fail("not a DOS-process");
FreeArgs(rdargs);
}
else
{
PrintFault(IoErr(),Basename);
ReturnCode = RETURN_FAIL;
};
}
else
Fail("needs dos.library v37 or higher");
return ReturnCode;
}